<?php
	header('content-type:text/html;charset=utf-8');
class CommentAction extends Action {
	public function index(){
		if(isset($_SESSION['uid'])){
			$m=M('Comment');
			import('ORG.Util.Page');
			$page=new Page($m->count(),5);
			$sql="SELECT cm.id as id,cm.cname as cname,cm.ctime as ctime,cm.ctext as ctext,cm.reply as reply,cm.url as url,cm.email as email,cn.title as title FROM lyolzj_comment as cm,lyolzj_content as cn where cm.artid=cn.id order by cm.id limit $page->firstRow,$page->listRows";
			$pageshow=$page->show();
			$this->assign('pageshow',$pageshow);
			$data=$m->query($sql);
			$this->assign('data',$data);
			$this->display();
		}
	}
	
	public function delete(){
		if(!isset($_SESSION['uid'])){
			$this->redirect('Index/login');
		}
		$where['id']=$this->_get('id');
		$m=M('Comment');
		$m->where($where)->delete() or $this->error('删除失败');
		$this->success('删除成功');
	}
	
	public function edit(){
		if(!isset($_SESSION['uid'])){
			$this->redirect('Index/login');
		}
		$m=M('Comment');
		$id=$this->_get('id');
		$sql="SELECT cm.id as id,cm.cname as cname,cm.ctime as ctime,cm.ctext as ctext,cm.reply as reply,cm.url as url,cm.email as email,cn.title as title FROM lyolzj_comment as cm,lyolzj_content as cn where cm.id=$id limit 1";
		$data=$m->query($sql);
		/*dump($data,true,'',false);
		exit;*/
		$this->assign('data',$data[0]);
		$this->display();
	}
	
	public function editok(){
		if(!isset($_SESSION['uid'])){
			$this->redirect('Index/login');
		}
		$m=M('Comment');
		$where['id']=$this->_post('id');
		$data['cname']=$this->_post('cname');
		$data['ctext']=$this->_post('ctext');
		$data['reply']=$this->_post('reply');
		$m->where($where)->save($data) or $this->error('编辑失败');
		$this->success('编辑成功','index');
	}
}
?>